var count = 1
var container = document.getElementById('container')

function getUserAction () {
  console.log('action')
  container.innerHTML = count++
}

function debounce (fn, wait = 1000, immediate = true) {
  var timer
  return function () {
    var context = this
    var args = arguments
    if (timer)  clearTimeout(timer)
    if (immediate) {
      var callNow = !timer
      timer = setTimeout(function () {
        timer = null
      }, wait)
      if (callNow)  fn.apply(context, args)
    } else {
      timer = setTimeout(function () {
        fn.apply(context, args)
      }, wait)
    }
  }
}

container.onmousemove = debounce(getUserAction, 1000, true)
